<?php
/**
 * Created by IntelliJ IDEA.
 * User: luwei
 * Date: 2017/11/15
 * Time: 17:52
 */
defined('IN_IA') or define('IN_IA', true);

class We7Db
{
    /**
     * @return array
     * 数据库配置 array<br>
     * [<br>
     *    'db_host' => '数据库服务器IP',<br>
     *    'db_name' => '数据库名称',<br>
     *    'db_user' => '数据库用户名',<br>
     *    'db_pwd' =>  '数据库密码',<br>
     *    'db_port' => '数据库端口',<br>
     * ]<br>
     */
    public static function getConfig()
    {
        error_reporting(E_ERROR);
        $config_file = __DIR__ . '/../../data/config.php';
        if (!file_exists($config_file))
            return [
                'db_host' => null,
                'db_name' => null,
                'db_user' => null,
                'db_pwd' => null,
                'db_port' => null,
            ];
        require $config_file;
        if (!empty($config['db']['master'])) {
            return [
                'db_host' => $config['db']['master']['host'],
                'db_name' => $config['db']['master']['database'],
                'db_user' => $config['db']['master']['username'],
                'db_pwd' => $config['db']['master']['password'],
                'db_port' => intval($config['db']['master']['port']),
            ];
        }
        return [
            'db_host' => $config['db']['host'],
            'db_name' => $config['db']['database'],
            'db_user' => $config['db']['username'],
            'db_pwd' => $config['db']['password'],
            'db_port' => intval($config['db']['port']),
        ];
    }
}